<template>
  <div class="tab-bar-item" @click="itemClick">
    <div v-if="!isActive"><slot name="item-icon"></slot></div>
    <div v-else><slot name="item-active-icon"></slot></div>
    <div :class="{ active: isActive }"><slot name="item-font"></slot></div>
  </div>
</template>
<script>
export default {
  name: "TabBarItem",
  props: {
    path: String,
  },
  computed: {
    isActive() {
      return this.$route.path.indexOf(this.path) !== -1;
    },
  },
  methods: {
    itemClick() {
      this.$router.replace(this.path);
    },
  },
};
</script>
<style >
.tab-bar-item {
  padding-top: 5px;
  text-align: center;
  font-size: 14px;
  flex: 1;
}
.tab-bar-item img {
  vertical-align: middle;
  padding-bottom: 2px;
  width: 24px;
}
.active {
  color: red;
}
</style>